(function ($) {
    $.fn.adsRotator = function() {
        var MAX_DISPLAYED=3;
                                    
              this.find('.carrousel_right').click(function(){
              
                  var parent=$(this).parent(".carrousel");                              
                                         
                  var position=parent.attr('data-pos');
                  position=parseInt(position, 10);
                  var elementsCount=parent.find('.carrousel_inner ul li').size();
                  lastPosition=elementsCount - MAX_DISPLAYED;
                  if (position<lastPosition)
                  {
                      position=position+1;
                      parent.find('.carrousel_left').removeClass('left_inactive');
                      if (position==lastPosition){
                          $(this).addClass('right_inactive');
                      }
                      var pos=position*200;
                      parent.attr('data-pos',position);
                      parent.find('.carrousel_inner').animate({'scrollLeft' : pos });
                  }
                  
                  return false;
              });
          
              this.find('.carrousel_left').click(function(){
                  var parent=$(this).parent(".carrousel");
                  
                  var position =parent.attr('data-pos');
                  var elementsCount=parent.find('.carrousel_inner ul li').size();
                  position=parseInt(position, 10);
                  if (position>0)
                  {
                      parent.find('.carrousel_right').removeClass('right_inactive');
                      position=position-1;
                      if(position==0)
                          {
                              $(this).addClass('left_inactive');
                          }
                      var pos=position*200;
                      parent.attr('data-pos',position);
                      parent.find('.carrousel_inner').animate({'scrollLeft' : pos });
                  }
                  
                  return false;
              });
              
              
          };

}) (jQuery)